package alo.p6.work4;

import alo.p6.BinarySearchTreeNode;

/**
 * @ClassName FindMin
 * @Description 在二叉搜索树中寻找最小元素
 * @Author Fanxc
 * @DATE 2021/2/10 10:20
 * @Version 1.0
 */
public class FindMin {
    //递归
    BinarySearchTreeNode findMin(BinarySearchTreeNode root){
        if (root==null){
            return null;
        }else if (root.getLeft()==null){
            return root;
        }else {
            return findMin(root.getLeft());
        }
    }
    //非递归
    BinarySearchTreeNode findMin2(BinarySearchTreeNode root){
        if (root==null){
            return null;
        }
        while (root.getLeft()!=null){
            root=root.getLeft();
        }
        return root;
    }
}
